﻿
operate_menue_view =
{    
    menu_ctrl_ptr_ = nil;
    menu_dark_ctrl_ptr_ = nil;
    menu_light_ctrl_ptr_ = nil;
    game_id_ = 0;
    color_mode_ =  MainCommon.color_mode.kDark;

    menue_id_to_index_ = {};   -- 控件id 对应的 index 索引
    INDEX_CLOSE_GAME = 1;     -- index 索引
    INDEX_MULTI_ZONE = 2;
    INDEX_MULTI_ACCOUNT = 3;
    INDEX_CLOUD_GAME = 4;
    INDEX_SERVER_INFO = 5;

    MAX_HISTORY_SERVER_SHOW = 3;  -- 最多显示多少个
    sub_menue_id_to_server_id_ = {};

    sub_menue_id_to_account_ = {};

    menu_item_hover_type = {
        hover_up = "9IMAGES:bottom_bar\\bottom_bar.png?379,130,387,138;bottom_bar\\bottom_bar.png?389,130,397,138;bottom_bar\\bottom_bar.png?399,130,407,138;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;Stretch;0;";
        hover_mid = "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;Stretch;0;";
        hover_down = "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,150,387,158;bottom_bar\\bottom_bar.png?389,150,397,158;bottom_bar\\bottom_bar.png?399,150,407,158;Stretch;null;";
        hover_updown = "9IMAGES:bottom_bar\\bottom_bar.png?379,130,387,138;bottom_bar\\bottom_bar.png?389,130,397,138;bottom_bar\\bottom_bar.png?399,130,407,138;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,150,387,158;bottom_bar\\bottom_bar.png?389,150,397,158;bottom_bar\\bottom_bar.png?399,150,407,158;Stretch;0;"; 
    };

    menu_item_hover_dark_type = {
        hover_up = "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;";
        hover_mid = "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;";
        hover_down = "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;";
        hover_updown = "ONEIMAGE:banner_menu\\menu_item_hover.png;Stretch;0;";
    };

    menu_item_hover_light_type = {
        hover_up = "9IMAGES:bottom_bar\\bottom_bar.png?379,130,387,138;bottom_bar\\bottom_bar.png?389,130,397,138;bottom_bar\\bottom_bar.png?399,130,407,138;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;Stretch;0;";
        hover_mid = "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?379,140,387,148;Stretch;0;";
        hover_down = "9IMAGES:bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,150,387,158;bottom_bar\\bottom_bar.png?389,150,397,158;bottom_bar\\bottom_bar.png?399,150,407,158;Stretch;null;";
        hover_updown = "9IMAGES:bottom_bar\\bottom_bar.png?379,130,387,138;bottom_bar\\bottom_bar.png?389,130,397,138;bottom_bar\\bottom_bar.png?399,130,407,138;bottom_bar\\bottom_bar.png?379,140,387,148;bottom_bar\\bottom_bar.png?389,140,397,148;bottom_bar\\bottom_bar.png?399,140,407,148;bottom_bar\\bottom_bar.png?379,150,387,158;bottom_bar\\bottom_bar.png?389,150,397,158;bottom_bar\\bottom_bar.png?399,150,407,158;Stretch;0;"; 
    };

    init = function()
        local main_uilib = ui_utility.uilib();
        local main_wnd_id = main_uilib:GetControlIDbyCustomID(CID_MAINFRAME_Dialog_MainFrame);
        if main_wnd_id ~= 0 then
            local const_ui_str, str_holder = U8toCUIStr("BottomOperateMenue");
            local id = main_uilib:GetControlIDbyPath(const_ui_str, main_wnd_id);
            operate_menue_view.menu_dark_ctrl_ptr_ = tolua.cast(
                                            main_uilib:GetControlPtr(id), "Tenio::IWinMenu");

            local const_ui_str2, str_holder2 = U8toCUIStr("BottomOperateLightMenue");
            id = main_uilib:GetControlIDbyPath(const_ui_str2, main_wnd_id);
            operate_menue_view.menu_light_ctrl_ptr_ = tolua.cast(
                                            main_uilib:GetControlPtr(id), "Tenio::IWinMenu");

            local color_data_config = comm_center.call_service("SvrTGPConfigMgr_GetColorMode", {});
            if color_data_config ~= nil and color_data_config.color_mode ~=nil then
                operate_menue_view.color_mode_ = color_data_config.color_mode;
            end;

            operate_menue_view.menu_ctrl_ptr_ = operate_menue_view.menu_dark_ctrl_ptr_;
            operate_menue_view.menu_item_hover_type = operate_menue_view.menu_item_hover_dark_type;
            if operate_menue_view.color_mode_ ==  MainCommon.color_mode.kLight then
                operate_menue_view.menu_ctrl_ptr_ = operate_menue_view.menu_light_ctrl_ptr_;
                operate_menue_view.menu_item_hover_type = operate_menue_view.menu_item_hover_light_type;
            end;
        end
    end;
    --[[
    @brief: 输入参数为banner上菜单按钮相对屏幕的位置
    ]]
    show = function(xoffset, yoffset, width, height, game_id)    
        local color_data_config = comm_center.call_service("SvrTGPConfigMgr_GetColorMode", {});
        if color_data_config ~= nil and color_data_config.color_mode ~=nil then
                operate_menue_view.color_mode_ = color_data_config.color_mode;
        end;
        operate_menue_view.menu_ctrl_ptr_ = operate_menue_view.menu_dark_ctrl_ptr_;
        operate_menue_view.menu_item_hover_type = operate_menue_view.menu_item_hover_dark_type;
         if operate_menue_view.color_mode_ ==  MainCommon.color_mode.kLight then
             operate_menue_view.menu_ctrl_ptr_ = operate_menue_view.menu_light_ctrl_ptr_;
             operate_menue_view.menu_item_hover_type = operate_menue_view.menu_item_hover_light_type;
        end;

        if nil == operate_menue_view.menu_ctrl_ptr_ then 
            return 
        end

        if operate_menue_view.menu_ctrl_ptr_ ~= nil and 
           operate_menue_view.menu_ctrl_ptr_:IsVisible() == TRUE then
            operate_menue_view.menu_ctrl_ptr_:Show(FALSE);
            return;
        end

        operate_menue_view.game_id_ = game_id;

        operate_menue_view.init_menue_item();

        --获取主窗口的位置
        local main_uilib = ui_utility.uilib();
        local main_wnd_id = main_uilib:GetControlIDbyCustomID(CID_MAINFRAME_Dialog_MainFrame);
        local main_wnd = main_uilib:GetControlPtr(main_wnd_id);
        local main_wnd_rc = main_wnd:GetRectEx(TRUE,TRUE);

        local rc = operate_menue_view.menu_ctrl_ptr_:GetRectEx(TRUE,TRUE);
        local w = rc.right - rc.left;
        local h = rc.bottom - rc.top;
        -- 获取系统工作区域大小：
        local tpf_ui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        local sys_param = ierd_tgp.tpf_ui.SysParams:new();
        tpf_ui:get_sys_params(sys_param);
        local work_area_height = sys_param.work_area_height;
        sys_param:delete();
        -- 菜单显示的位置
        local menu_xoffset = 6;
        rc.left = xoffset - main_wnd_rc.left - w + width - menu_xoffset;
        rc.right = rc.left + w;
        local menu_yoffset = yoffset - h - 4;
        rc.top = menu_yoffset - main_wnd_rc.top;
        rc.bottom = rc.top + h;
        operate_menue_view.menu_ctrl_ptr_:MoveEx(rc,TRUE);
        operate_menue_view.menu_ctrl_ptr_:Show(TRUE);
    end;

    -- 隐藏菜单栏
    hide = function()
        if operate_menue_view.menu_ctrl_ptr_ ~= nil then
            operate_menue_view.menu_ctrl_ptr_:Show(FALSE);
        end
    end;

    -- 初始化菜单栏item
    init_menue_item = function()
        if operate_menue_view.menu_ctrl_ptr_ ~= nil then
             operate_menue_view.menu_ctrl_ptr_:RemoveAll();
        end
        operate_menue_view.menue_id_to_index_ = {};
        -- 设置要显示的menu
        operate_menue_view.set_client_game_menue();
    end;

    -- 设置游戏菜单栏
    set_client_game_menue = function()
        local main_uilib = ui_utility.uilib();
        -- 先算出总数量，用于设置不同样式
        local total_count, item_status = operate_area.get_menu_item_total_count();

        local menu_item_index = -1;
        -- 大区选择
        if item_status.server_info == true then
            menu_item_index = menu_item_index + 1;
            local server_info_status = operate_area.get_server_info_status();
            local id = operate_menue_view.add_server_info_menue_item(
                                            server_info_status, menu_item_index, total_count);
            if id ~= 0  then
                operate_menue_view.menue_id_to_index_[id] = operate_menue_view.INDEX_SERVER_INFO;
            end;
        end;

        -- 云游戏
       --[[ if item_status.cloud_game == true then
            menu_item_index = menu_item_index + 1;
            local cloud_game_entry_status = operate_area.get_cloud_game_entry_status();
            if cloud_game_entry_status ~= nil and cloud_game_entry_status.visible == true then
                local show_text = cloud_game_entry_status.show_txt;
                if show_text == "" then
                    show_text = LoadStr("FRAME_BOTTOM_CLOUD_GAME_START");
                end;
                local id = operate_menue_view.add_normal_menue_item(
                                                show_text, menu_item_index, total_count);
                if id ~= 0  then
                    operate_menue_view.menue_id_to_index_[id] = operate_menue_view.INDEX_CLOUD_GAME;
                end;
            end;
        end;
        ]]--
        -- 小号多开
        if item_status.multi_account == true then
            menu_item_index = menu_item_index + 1;
            local id = 
                    operate_menue_view.add_multi_account_menue_item(menu_item_index, total_count);
            if id ~= 0  then
                operate_menue_view.menue_id_to_index_[id] = operate_menue_view.INDEX_MULTI_ACCOUNT;
            end;
        end;

        -- 单号多开
        if item_status.multi_zone == true then
            menu_item_index = menu_item_index + 1;
            local str_multi_zone = LoadStr(ID_MULI_ZONE);
            local id = operate_menue_view.add_normal_menue_item(
                                                str_multi_zone, menu_item_index, total_count);
            if id ~= 0  then
                operate_menue_view.menue_id_to_index_[id] = operate_menue_view.INDEX_MULTI_ZONE;
            end;
        end;

        -- 关闭游戏
        if item_status.exit_game == true then
            menu_item_index = menu_item_index + 1;
            local str_close_game = LoadStr(ID_CLOSE_GAME);
            local id = operate_menue_view.add_normal_menue_item(
                                                str_close_game, menu_item_index, total_count);
            if id ~= 0  then
                operate_menue_view.menue_id_to_index_[id] = operate_menue_view.INDEX_CLOSE_GAME;
            end;
        end;
    end;

    set_btn_state = function(item_index, total_item, id, text_str)
        local split_line_visible = "false";
        local item_id = ui_utility.get_ctrl_id_by_path(id, "ItemBtn");
        if item_index == 0 and total_item == 1 then
            -- 只有一个菜单项
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                operate_menue_view.menu_item_hover_type.hover_updown);
        elseif item_index == 0 and total_item > 1 then
            -- 有多个菜单项，当前是第一个
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                operate_menue_view.menu_item_hover_type.hover_up);
            split_line_visible = "true";
        elseif item_index > 0 and item_index < (total_item - 1) then
            -- 有多个菜单项，当前是中间项
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                operate_menue_view.menu_item_hover_type.hover_mid);
            split_line_visible = "true";
        elseif item_index > 0 and item_index == (total_item - 1) then
            -- 有多个菜单项，当前是最后一个
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                operate_menue_view.menu_item_hover_type.hover_down);
        end;

        -- 设置显示文本
        ui_utility.setproperty_by_path(id, "ItemBtn", "Caption", text_str);

        -- 设置分隔线
        ui_utility.setproperty_by_path(id, "SplitLine", "Visible", split_line_visible);

        -- 获得btnid 返回
        return item_id;
    end;

    -- 添加文字菜单项
    add_normal_menue_item = function(text_str, item_index, total_item)
        local tpf_file = "frame_bottom\\OperateMenueItemNormal.tpf";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
              tpf_file = "frame_bottom\\dark_mode\\OperateMenueItemNormal.tpf";
        end;
        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local id = operate_menue_view.menu_ctrl_ptr_:AppendItem(const_ui_str);
        if id ~= 0 then
            operate_menue_view.set_btn_state(item_index, total_item, id, text_str);
        else
            base_utility.log("add_normal_menue_item error! ")
        end
        return id;
    end;
    
    -- 大区信息
    add_server_info_menue_item = function(server_info_status, item_index, total_item)
        local tpf_file = "frame_bottom\\OperateMenueItemServerInfo.tpf";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
            tpf_file = "frame_bottom\\dark_mode\\OperateMenueItemServerInfo.tpf";
        end;
        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local id = operate_menue_view.menu_ctrl_ptr_:AppendItem(const_ui_str);
        if id ~= 0 then
            operate_menue_view.set_server_info_menu_state(
                                            item_index, total_item, id, server_info_status);
            operate_menue_view.set_server_info_sub_menu(item_index);
        else
            base_utility.log("add_normal_menue_item error! ")
        end
        return id;
    end;

    set_server_info_menu_state = function(item_index, total_item, id, server_info_status)
        --[[server_info_status = {
            visible = false,
            enable = false,
            show_txt = "",
            delay_txt_status = "",
            state_icon = "",
        };
        local delay_txt_status = {
            visible = false,
            color = "",
            text = "",
        };--]]

        local text_str = server_info_status.show_txt;
        local disable = "false";
        if server_info_status.enable == false then
            disable = "true";
        end;

       local item_id = ui_utility.get_ctrl_id_by_path(id, "ItemBtn");
        if item_index == 0 and total_item == 1 then
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_updown);
        elseif item_index == 0 and total_item > 1 then
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_up);
        elseif item_index > 0 and item_index < (total_item - 1) then
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_mid);
        elseif item_index > 0 and item_index == (total_item - 1) then
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_down);
        end;

        -- 设置显示文本
        ui_utility.setproperty_by_path(id, "ItemBtn", "Caption", text_str);
        -- 是否可响应
        ui_utility.setproperty_by_path(id, "ItemBtn", "Disable", disable);
        -- 延迟
        local delay_txt_status = server_info_status.delay_txt_status;
        if delay_txt_status ~= nil and delay_txt_status.visible == true and 
           delay_txt_status.text ~= "" then
            ui_utility.setproperty_by_path(id, "delayTime", "TextColor", 
                                                            delay_txt_status.color); 
            ui_utility.setproperty_by_path(id, "delayTime", "TextColorHover", 
                                                            delay_txt_status.color);
            ui_utility.setproperty_by_path(id, "delayTime", "TextColorPressed", 
                                                            delay_txt_status.color);
            ui_utility.setproperty_by_path(id, "delayTime", "Caption", delay_txt_status.text);

            ui_utility.setproperty_by_path(id, "delayTime", "Visible", "true");
        else
            ui_utility.setproperty_by_path(id, "delayTime", "Visible", "false");
        end;

        return item_id;
    end;

    set_server_info_sub_menu = function(parent_index)
        local game_id = operate_menue_view.game_id_;
        -- 创建子菜单
        local tpf_file = "frame_bottom\\OperateSubMenueZoneList.tpf";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
            tpf_file = "frame_bottom\\dark_mode\\OperateSubMenueZoneList.tpf";
        end;

        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local sub_menu_ptr = nil;
        sub_menu_ptr = operate_menue_view.menu_ctrl_ptr_:AppendSubMenu(
                                            parent_index, const_ui_str, Tenio.SMSP_AUTO);

        local servers = banner_model.get_game_servers(game_id);
        if servers.selleted == 0 then
            base_utility.log("no selected servers", true);
            local item_id = operate_menue_view.add_other_zone_item(sub_menu_ptr, game_id, true);
            ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                    operate_menue_view.menu_item_hover_type.hover_updown);
            return nil;
        end
                
        -- 插入大区列表项数量限制
        local server_count = operate_menue_view.MAX_HISTORY_SERVER_SHOW;
        if(servers.server_count < server_count) then
           server_count = servers.server_count;
        end
                
        for i= 0, server_count - 1 do
            local server_info = servers.servers[i];
    
            if server_info ~= nil then
                base_utility.log(string.format("set server info %d(%d, %s)",
                                      i, server_info.id, server_info.name));
                local item_id = operate_menue_view.add_zone_item(
                                            sub_menu_ptr, game_id, server_info);
                if i == 0 then
                    ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                            operate_menue_view.menu_item_hover_type.hover_up); 
                else
                    ui_utility.setproperty_by_id(item_id, "BackgroundHover", 
                                            operate_menue_view.menu_item_hover_type.hover_mid); 
                end
            else
                base_utility.log(string.format("servers.servers[%d] == nil", i), true);
            end;
        end;
        
        local other_item_id = operate_menue_view.add_other_zone_item(sub_menu_ptr, game_id, false);
        if server_count == 0 then
            ui_utility.setproperty_by_id(other_item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_updown);
        else
            ui_utility.setproperty_by_id(other_item_id, "BackgroundHover", 
                                        operate_menue_view.menu_item_hover_type.hover_down);
        end 
    end;

    add_other_zone_item = function(sub_menu_ptr, game_id, is_init)
        local item_id = operate_menue_view.add_zone_item_impl(sub_menu_ptr);
        if item_id == Tenio.INVALID_CONTROLID then
            base_utility.log("item id is INVALID_CONTROLID", true);
            return item_id;
        end        
        
        -- 显示其他大区选项
        ui_utility.show_only_child(item_id, "TxtOtherZone");
        local other_text = LoadStr("FRAME_BOTTOM_OTHER_ZONE_INIT");
        ui_utility.set_static_text(item_id, "TxtOtherZone", other_text);
        return item_id;
    end;
    
    add_zone_item = function(sub_menu_ptr, game_id, server_info)
        if server_info == nil then
            base_utility.log("server_info is NIL", true);
            return Tenio.INVALID_CONTROLID;
        end
        
        local item_id = operate_menue_view.add_zone_item_impl(sub_menu_ptr, server_info.id);
        if item_id == Tenio.INVALID_CONTROLID then
            base_utility.log("item id is INVALID_CONTROLID", true);
            return item_id;
        end        
        
        ui_utility.show_only_child(item_id, "UobContent");
        local split_line_ptr = ui_utility.get_ctrl_ptr_by_path(item_id, "SplitLine");
        if nil ~= split_line_ptr then
            split_line_ptr:Show(TRUE);
        end
        WGSelectZoneItem:set_item_or_edit(item_id, game_id, server_info);
        return item_id;
    end;
    
    add_zone_item_impl = function(sub_menu_ptr, zone_id)
        if sub_menu_ptr == nil then
            base_utility.log("sub_menu_ptr is NIL", true);
            return Tenio.INVALID_CONTROLID;
        end
        local tpf_file = "BannerZoneForPlugin.tpf/TenioUILayout/UIObject/Children/UIObject?CntItem";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
            tpf_file = "BannerZoneDarkForPlugin.tpf/TenioUILayout/UIObject/Children/UIObject?CntItem";
        end;
        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local item_id = sub_menu_ptr:AppendItem(const_ui_str);
        if item_id == Tenio.INVALID_CONTROLID then
            base_utility.log("added item fail, ".. " for zone:" .. tostring(zone_id), true);
            return Tenio.INVALID_CONTROLID;
        end
        
        base_utility.log("added item:"..tostring(item_id).. " for zone:"..tostring(zone_id));
        operate_menue_view.sub_menue_id_to_server_id_[item_id] = zone_id;
        
        return item_id;
    end;


    on_server_info_item_mouse_hover = function(uilib, control_id)
        --[[local ptr  = ui_utility.get_ctrl_ptr_by_id(control_id);
        local x_offset = 0;
        local y_offset = 0;

        if nil ~= ptr then
            local rc = ptr:GetRectEx(TRUE,TRUE);
            x_offset = rc.right + 1;
            y_offset = rc.top;
            WGSelectZoneList.init(WGSelectZoneList.LIST_TYPE.FOR_PLUGIN_PAGE);
            WGSelectZoneList.show(x_offset, y_offset, operate_menue_view.game_id_);
        end;--]]
    end;

    on_server_info_item_mouse_leave = function()
    end;

    add_multi_account_menue_item = function(item_index, total_item)
        local str_multi_account = LoadStr(ID_CHOOSE_ACC);
        local id = operate_menue_view.add_normal_menue_item(
                                            str_multi_account, item_index, total_item);
        operate_menue_view.set_multi_account_sub_menu(item_index);
        return id;
    end;

    -- 添加小号列表
    set_multi_account_sub_menu = function(parent_index)
        local tpf_file = "frame_bottom\\OperateSubMenueAccList.tpf";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
            tpf_file = "frame_bottom\\dark_mode\\OperateSubMenueAccList.tpf";
        end;
        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local sub_menu_ptr = nil;
        sub_menu_ptr = operate_menue_view.menu_ctrl_ptr_:AppendSubMenu(
                                            parent_index, const_ui_str, Tenio.SMSP_AUTO);

        operate_menue_view.sub_menue_id_to_account_ = {};

        local acc_list = operate_menue_view.get_sub_account_list();
        -- 加1是因为"添加帐号"按钮
        local acc_count = acc_list.count + 1;
        for i = 0, acc_list.count - 1 do 
            local acc = acc_list.uins[i];
            operate_menue_view.add_account_item(sub_menu_ptr, true, i, acc_count, acc);
        end;

        -- 添加添加小号按钮
        operate_menue_view.add_account_item(sub_menu_ptr, false, acc_count - 1, acc_count);
    end;

    get_sub_account_list = function()
        local loginlib =
            base_utility.get_component_adapter("ILogin_mgr",
                "ierd_tgp.login_mgr.GetLoginMgr();");
        subacclist = ierd_tgp.login_mgr.SubAccountListPod:new_local();
        loginlib:GetSubAccountList(subacclist);
        ierd_tgp.tpf_ui.Log("subacclist "..subacclist.count);
        for i = 1, subacclist.count do 
            ierd_tgp.tpf_ui.Log("subacclist uin:"..subacclist.uins[i-1]);
        end;
        return subacclist;
    end;

    -- 添加单个uin元素
    add_account_item = function(sub_menu_ptr, is_acc, cur_index, total_num, acc)
        local main_uilib = ui_utility.uilib();
        local item_content = "";
        if is_acc == true then
            if acc ~= nil and acc ~= 0 then
                item_content = tostring(acc);
            end;
        else
            item_content = LoadStr(ID_ADD_SUB_QQ);
        end;

        local tpf_file = "frame_bottom\\OperateMenueItemAccInfo.tpf";
        if operate_menue_view.color_mode_ == MainCommon.color_mode.kDark then
            tpf_file = "frame_bottom\\dark_mode\\OperateMenueItemAccInfo.tpf";
        end;
        local const_ui_str, str_holder = U8toCUIStr(tpf_file);
        local id = sub_menu_ptr:AppendItem(const_ui_str);

        if id ~= 0 then
            local btn_id = operate_menue_view.set_btn_state(cur_index, total_num, id, item_content);
            local const_ui_str2, str_holder2 = U8toCUIStr("Btn_Delete");
            local delete_btn_id = main_uilib:GetControlIDbyPath(const_ui_str2, id);
            if is_acc == true then
                operate_menue_view.sub_menue_id_to_account_[btn_id] = acc;
                operate_menue_view.sub_menue_id_to_account_[delete_btn_id] = acc;
                ui_utility.setproperty_by_id(delete_btn_id, "Visible", "true");
            else
                ui_utility.setproperty_by_id(delete_btn_id, "Visible", "false");
            end;
        else
            base_utility.log("add_account_item error! ")
        end
    end;


    -- 点击列表时的响应函数
    on_click_item = function(uilib, id, item_id, item_index)
        local index_type = operate_menue_view.menue_id_to_index_[item_id];
        if index_type == operate_menue_view.INDEX_CLOSE_GAME then
            -- 关闭游戏功能实现
            operate_menue_view.on_close_game_click(item_id);
        elseif index_type == operate_menue_view.INDEX_CLOUD_GAME then
            operate_menue_view.on_cloud_game_click(item_id);
        elseif index_type == operate_menue_view.INDEX_SERVER_INFO then
        elseif index_type == operate_menue_view.INDEX_MULTI_ZONE then
            operate_menue_view.on_multi_zone_click(item_id);
        else
            base_utility.log("index type is valid type!!!");
        end;
        return true;
    end;

    on_select_item = function(uilib, id, item_id, item_index)
        return 0;
    end;

    on_zone_list_sub_item_click = function(uilib, id, item_id, item_index)
        local server_id = operate_menue_view.sub_menue_id_to_server_id_[item_id];

        local game_id = operate_menue_view.game_id_;
        if game_id == nil or game_id == 0 then
        base_utility.log("invalid current game:"..tostring(game_id), true);
             return;
        end
     
        if server_id ~= nil and server_id ~= 0 then
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            if game_lib ~= NULL then
                game_lib:set_last_selected_server(game_id, server_id);
            end;
        else
            -- 大区ID填0，启动游戏即打开选区界面
            -- 网页游戏zone_id = 0 && version="web_game_select_zone",启动游戏即打开选区界面
            local action_info = {
                      game_id_ = game_id,
                      zone_id_ = 0,  -- 大区填0，打开选区界面
                      uid_ = 0,
                      version_ = "web_game_select_zone",
                      launch_op_from = ierd_tgp.game_library.LAUNCH_OP_FROM_MAIN_WND
                  };
         
            WGGameAction.excute_action(GameActions.kStartGame, action_info);
        end
        return true;
    end;

    start_acc = function(uilib, dwControlId)
        if operate_menue_view.sub_menue_id_to_account_[dwControlId] ~= nil then
            -- 点击的是QQ号
            sub_account_mgr.login_sub_account(operate_menue_view.game_id_,
                        operate_menue_view.sub_menue_id_to_account_[dwControlId],
                        ierd_tgp.game_library.LAUNCH_OP_FROM_MAIN_WND);
            
        else
            -- 点击的是添加小号
            operate_menue_view.add_acc();
        end
    end;

    -- 添加帐号按钮响应
    add_acc = function()
        local acc_list = operate_menue_view.get_sub_account_list();
        if acc_list.count >= 3 then
            local param = {
                first_line = LoadStr(ID_TOMUCH_SUB_ACCOUNT_TIP_FIRST),
                second_line = LoadStr(ID_TOMUCH_SUB_ACCOUNT_TIP_SECOND),
                icon = "ONEIMAGE:bottom_bar\\tips_icon\\red_icon.png;Stretch;0;",
            }
            event_center.send_event(sub_account_login_event.SUB_ACCOUNT_SHOW_TIPS, 
                base_utility.table_to_json(param));
        else
            local info = {game_id = operate_menue_view.game_id_};
            event_center.send_event(sub_account_login_event.SUB_ACCOUNT_ADD_ACCOUNT, 
                base_utility.table_to_json(info));
        end;
        return true;
    end;

    -- 删除小号
    delete_acc = function(uilib, dwControlId)
        if operate_menue_view.sub_menue_id_to_account_[dwControlId] ~= nil then
            sub_account_mgr.del_sub_account(
                operate_menue_view.sub_menue_id_to_account_[dwControlId]);
        else
            base_utility.log("delete_acc acc error!!!");
        end
    end;

    on_show = function()
    end;

    on_hide = function()
    end;

    -- 关闭游戏功能实现
    on_close_game_click = function(item_id)
        base_utility.log("close game");
        operate_menue_control.excute_game_act(GameActions.kStopGame,
                    operate_menue_view.game_id_, 0);
    end;

    -- 多区双开实现
    on_multi_zone_click = function (item_id)
        local game_id = operate_menue_view.game_id_;
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib then
            game_lib:LaunchGameTcls(game_id);
        else
            base_utility.log("open mult zone, get game_lib failed");
            return;
        end;
    end;

    on_cloud_game_click = function(item_id)
        local tool_panel = operate_area.get_tool_panel();
        if tool_panel ~= nil then
            tool_panel.on_cloud_game_btn_click();
        end;
    end;
};

operate_menue_view.init();
